<!--
    -  Copyright (c) 2018-2025, haohanwork.com All rights reserved.
  -->
<template>
    <div class="execution">
        <basic-container>
            <h2 class="io-goods-detail">基础信息</h2>
            <template>
                <el-row class="io-goods-detail basic-information">
                    <el-col :span="6">
                        <div class="grid-content bg-purple">入库单号：{{basicInformation.enterWarehouseSn}}</div>
                    </el-col>
                    <el-col :span="6">
                        <div class="grid-content bg-purple-light">入库类型：{{basicInformation.enterType}}</div>
                    </el-col>
                    <el-col :span="6">
                        <div class="grid-content bg-purple"></div>
                        入库状态：{{basicInformation.enterStatus}}
                    </el-col>
                </el-row>
                <el-row class="io-goods-detail basic-information">
                    <el-col :span="6">
                        <div class="grid-content bg-purple-light"></div>
                        创建日期：{{basicInformation.createDate}}
                    </el-col>
                    <el-col :span="6">
                        <div class="grid-content bg-purple">关联单号：{{basicInformation.deliveryTime}}</div>
                    </el-col>
                    <el-col :span="6">
                        <div class="grid-content bg-purple-light">制单人：{{basicInformation.createBy}}</div>
                    </el-col>
                </el-row>
                <el-row class="io-goods-detail basic-information">
                    <el-col :span="6">
                        <div class="grid-content bg-purple"></div>
                        仓库：{{basicInformation.warehouseSn}}
                    </el-col>
                    <el-col :span="6">
                        <div class="grid-content bg-purple"></div>
                        备注：{{basicInformation.remarks}}
                    </el-col>
                </el-row>
            </template>
        </basic-container>
        <basic-container>
            <h2 class="io-goods-detail">单据详情</h2>
            <template>
                <el-table :data="tableData" border :summary-method="getSummaries"  show-summary style="width: 100%">
                    <el-table-column prop="id" label="序号" type="index" width="180px"></el-table-column>
                    <el-table-column prop="productName" label="商品"></el-table-column>
                    <el-table-column prop="unit" sortable label="单位"></el-table-column>
                    <el-table-column prop="productNumber" label="入库数量"></el-table-column>
                </el-table>
            </template>
        </basic-container>
    </div>
</template>
<!-- 采购退货 -->
<script>
    import {
        queryList,
    } from '@/api/scm/warehouse/enter_warehouse'
    import {
        tableOption
    } from '@/const/crud/scm/warehouse/enter_warehouse'
    import {mapGetters} from "vuex";
    import Util from '@/util/pds/utils'
    let cookieUtil = new Util();
    import {getStore, setStore} from "@/util/store";
    export default {
        name: "addpurchaseback",
        data() {
            return {
                //入库单详情列表
                tableData: [],
                otherMoney: 100,
                calcMoney: 1000,
                //入库单信息
                basicInformation: {},
                //修改记录
            };
        },
        computed: {
            ...mapGetters(["permissions"])
        },
        created(){
            this.init();
        },
        methods: {
            init() {
                let param = {};
                param.pmId= getStore({name: "pmId"});
                param.enterWarehouseSn = this.$route.query.enterWarehouse.enterWarehouseSn;
                queryList(param).then(res =>{
                    this.basicInformation = res.data.data;
                    this.tableData = res.data.data.list;
                })
            },
            // 数据合计
            getSummaries(param){
                const { columns, data } = param;
                const sums = [];
                columns.forEach((column, index) => {
                    if (index === 0) {
                        sums[index] = '合计';
                        return;
                    }else if(index !== 3 && index !== 5 ){
                        sums[index] = '';
                        return;
                    }
                    const values = data.map(item => Number(item[column.property]));
                    if (!values.every(value => isNaN(value))) {
                        sums[index] = values.reduce((prev, curr) => {
                            const value = Number(curr);
                            if (!isNaN(value)) {
                                return prev + curr;
                            } else {
                                return prev;
                            }
                        }, 0);
                        sums[index] = sums[index].toFixed(2);
                    } else {
                        sums[index] = 'N/A';
                    }
                });
                return sums;
            },

            backup: function () {
                this.$router.go(-1);
            }
        }
    };
</script>

<style lang="scss" scoped>
    .io-goods-detail {
        margin-bottom: 10px;
    }

    .settle-accounts {
        text-align: right;
    }

    .basic-information {
        margin-top: 20px;
        font-weight: inherit;
    }

    .return-btn {
        height: 100px;
        width: 100%;
        text-align: center;
        line-height: 100px;
    }
</style>
